var app=app||{};
(function(){
	var AppView=Backbone.View.extend({
		el:"#app",
		events:{
			"click #addUser":"addUserHandle"
		},
		initialize:function(){
			this.listenTo(this.model,"add",this.addOne);
			this.model.fetch();
		},
		addOne:function(u){
			var view=new app.UserView({model:u});
			this.$("#user-list").append(view.render().el);
		},
		addUserHandle:function(event){
			var uname=$("input[name='uname']").val();
			var age=$("input[name='age']").val();
			var u=new app.User({uname:uname,age:age});
			this.model.create(u);
		},
	})
	var appView=new AppView({model:users});
	app.appView=appView;
})();
